//
// Created by jinbang.li on 2023/4/8.
//

#include "OpData.h"
extern "C" {
#include <libavformat/avformat.h>
}
bool OpData::alloc(int size, const char *data) {
    dropData();
    type = UCHAR_TYPE;
    if (size <= 0){
        return false;
    }
    this->data = new unsigned char [size];
    if (!this->data) return false;
    if (data){
        memcpy(this->data,data,size);
    }
    this->size = size;
    return true;
}
void OpData::dropData() {
    if (!data) return;
    if (type == AVPACKET_TYPE)
    av_packet_free((AVPacket **)&data);
    else
        delete data;
    data = 0;
    size = 0;
}